package com.horizon.manage.site.converter;

import com.horizon.common.context.HorizonContext;
import com.horizon.common.converter.HorizonBaseEvdConverter;
import com.horizon.manage.site.dto.SiteDTO;
import com.horizon.manage.site.entity.Site;
import com.horizon.manage.site.service.ISiteService;
import com.horizon.manage.site.vo.SiteVO;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 场地entity、vo、dto转换器.
 *
 * @author zhaoshb
 * @since 2022/12/5 23:57
 */
@Component
public class SiteEvdConverter extends HorizonBaseEvdConverter<Site, SiteVO, SiteDTO> {

    @Override
    public SiteVO entityToVO(Site entity) {
        SiteVO siteVO = new SiteVO();
        siteVO.setId(entity.getId());
        siteVO.setName(entity.getName());
        siteVO.setSupportItemList(querySupportItemList(entity.getId()));
        return siteVO;
    }

    @Override
    public Site dtoToEntity(SiteDTO dto) {
        Site site = new Site();
        site.setId(dto.getId());
        site.setTenantId(dto.getTenantId());
        site.setName(dto.getName());
        return site;
    }

    public List<Long> querySupportItemList(Long siteId) {
        ISiteService siteService = HorizonContext.getBean(ISiteService.class);
        return siteService.querySiteSupportItemList(siteId);
    }
}
